import { Injectable } from "@nestjs/common";
import { CreateUploadDto } from "./dto/create-upload.dto";
import { UpdateUploadDto } from "./dto/update-upload.dto";
import { InjectRepository } from "@nestjs/typeorm";
import { Upload } from "./entities/upload.entity";
import { In, Repository } from "typeorm";
import { plainToInstance } from "class-transformer";
import { FileDto } from "./dto/FileDto";

@Injectable()
export class UploadService {
  constructor(
    @InjectRepository(Upload)
    private readonly fileRepository: Repository<Upload>,
  ) {}

  create(createUploadDto: CreateUploadDto) {
    const upload = plainToInstance(Upload, createUploadDto);
    return this.fileRepository.save(upload);
  }

  /*
   * 根据文件id返回文件
   * */
  async findOne(fileDto: FileDto) {
    return await this.fileRepository.findOne({
      where: {
        id: fileDto.fileId,
      },
    });
  }
}
